#include "automatic.h"
#include "ui_automatic.h"
#include<QThread>
#include<QTimer>
#include<QDir>
#include<QMessageBox>
#include <QCoreApplication>
#include <QDir>
#include"signsls_slots.h"
//YKTdEZUvUmjt44Ek5ptecsiR
//DIFEO60TWXqMyTZV7RBEHecQaB0qdpM9
automatic::automatic(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::automatic),
    m_hub(&SignslS_SlotS::getInstance())
{

    ui->setupUi(this);
    speech = new speechrecognition(this);
    ui->stop_btn->setEnabled(false);
    connect(this,&automatic::openlight,m_hub,&SignslS_SlotS::openlight);
}

automatic::~automatic()
{
    delete ui;
}



void automatic::on_start_btn_clicked()
{



      /* 点击Start后禁用Start，开放Stop按钮 */
     ui->start_btn->setEnabled(false);
     QString appDir = QCoreApplication::applicationDirPath();
     QDir::setCurrent(appDir);  // 设置工作目录为程序所在目录

     // 然后可以用相对路径
     QString dbPath = "1.pcm";  // 相对于可执行文件目录
     ui->stop_btn->setEnabled(true);

     myAudioCapture.startCapture(dbPath);  //开始录音

}

void automatic::on_stop_btn_clicked()
{
    QString appDir = QCoreApplication::applicationDirPath();
    QDir::setCurrent(appDir);  // 设置工作目录为程序所在目录

    // 然后可以用相对路径
    QString dbPath = "1.pcm";  // 相对于可执行文件目录
    qDebug() << "应用程序目录：" << appDir;
    qDebug() << "相对路径：" << dbPath;
    qDebug() << "绝对路径：" << QFileInfo(dbPath).absoluteFilePath();
    qDebug() << "文件是否存在：" << QFile::exists(dbPath);
    qDebug() << "当前工作目录：" << QDir::currentPath();
    myAudioCapture.stopCapture();  //开始录音
    ui->start_btn->setEnabled(true);
    ui->stop_btn->setEnabled(false);
    QString result = speech->speechIdentify(dbPath);
    if(result!=""){
        ui->filepath->setText(result);
        if(result=="打开灯光。"){
            qDebug()<<1233333;
            emit openlight();
        }
    }
    else{
        QMessageBox::warning(NULL,"错误提示","识别失败");
    }
}

void automatic::on_pushButton_clicked()
{
    emit showMenu();
}
